package reliability.types.graph;

public class Edge
    extends NetworkElement
{
    private double reliability;
    private Integer node1Key;
    private Integer node2Key;
    private boolean isReservedLine = false;

    public Edge(double reliability, int node1Key, int node2Key)
    {
        super(reliability);
        this.node1Key = node1Key;
        this.node2Key = node2Key;
    }

    public Integer getNode1Key()
    {
        return node1Key;
    }

    public Integer getNode2Key()
    {
        return node2Key;
    }

    public void setNode1Key(Integer node1Key)
    {
        this.node1Key = node1Key;
    }

    public void setNode2Key(Integer node2Key)
    {
        this.node2Key = node2Key;
    }

    public Integer getNeighbourKey(Integer nodeKey)
    {
        Integer neighbourKey = null;
        if (nodeKey.equals(node1Key))
        {
            neighbourKey = node2Key;
        }
        else if (nodeKey.equals(node2Key))
        {
            neighbourKey = node1Key;
        }
        return neighbourKey;
    }

    public void setReservedLine(boolean isReservedLine)
    {
        this.isReservedLine = isReservedLine;
    }

    public boolean isReservedLine()
    {
        return isReservedLine;
    }

    public boolean hasSameEnds(Edge edge)
    {
        return (node1Key.equals(edge.getNode1Key()) && node2Key.equals(edge.getNode2Key()))
                || (node1Key.equals(edge.getNode2Key()) && node2Key.equals(edge.getNode1Key()));
    }
}
